package com.acme.bankapp.service;
import com.acme.bankapp.domain.*;

import java.util.*;

public class BankReport {

	public static int getNbOfCustomers(Bank bank) {
		return bank.getNumberOfClients();
	}
	
	public static int getNbOfAccounts (Bank bank) {
		int num = 0;
		for (Client cli : bank.getClients()) {
			 num += cli.getNumberOfAccounts();
		}
		return num;
	}
	public static List<Account> getAccountsSortedBySum (Bank bank) {
		List<Account> accs = new ArrayList<Account>();
		for (Client cli : bank.getClients()) {
			accs.addAll(cli.getAccounts());
		}
		Comparator<Account> c = new Comparator<Account>() {
			public int compare(Account o1, Account o2) {
				return (int)(o1.decimalValue() - o2.decimalValue());
			}
		};
		Collections.sort(accs, c);
		return accs;
	}
	public static double getBankCredit (Bank bank) {
		double over = 0.;
		for (Client cli : bank.getClients()) {
			for (Account acc : cli.getAccounts()) {
				if (acc instanceof CheckingAccount) {
					over += ((CheckingAccount) acc).getOverdraft();
				}
			}
		}
		return over;
	}
	
	public static Map<Client, List<Account>> getCustomerAccount(Bank bank) {
		Map<Client, List<Account>> map = new HashMap<Client, List<Account>>();
		for (Client cli : bank.getClients()) {
			List<Account> accs = new ArrayList<Account>();
			accs.addAll(cli.getAccounts());
			map.put(cli, accs);
		}
		return map;
	}
}
